﻿#include "stdafx.h"
#include "main_data_c.h"
#include "ui/msgbox.h"
#include "utils/Debug.h"
#include "GameNet.h"

static GameNet* s_gameNet;

GameNet::GameNet()
{
}

GameNet* GameNet::getInstance()
{
	if (!s_gameNet)
		s_gameNet = new GameNet;
	return s_gameNet;
}

void GameNet::connect(const char* ip, u_short port)
{
	netConnect(ip, port);
}

void GameNet::close()
{
	m_mySocket.close();
}

int GameNet::onAsyncRecv()
{
    return m_mySocket.onAsyncRecv();
}

void GameNet::onAsyncSend()
{
    m_mySocket.onAsyncSend();
}

void GameNet::dispatchPackets()
{
	BYTE* data;
	while (1)
	{
		data = m_mySocket.checkDataBuf();
		if (!data) return;

        m_protocol.handlePacket(data);
	}
}
